package com.aaa.mbs.controller;

import com.aaa.common.constants.ReturnStatus;
import com.aaa.common.util.Result;
import com.aaa.mbs.entity.CarComment;
import com.aaa.mbs.service.CarCommentService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

/**
 * (CarComment)表控制层
 *
 * @author makejava
 * @since 2020-12-05 14:54:00
 */
@RestController
@RequestMapping("carComment")
public class CarCommentController {
    /**
     * 服务对象
     */
    @Resource
    private CarCommentService carCommentService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    @ApiOperation("通过主键查询单条数据")
    public CarComment selectOne(Integer id) {
        return this.carCommentService.queryById (id);
    }

    /**
     * 查询所有分页加条件查询
     *
     * @param pageNo     第几页
     * @param pageSize   每页显示数量
     * @param carComment 实体
     * @return Result
     */
    @PostMapping("queryAll")
    @ApiOperation("查询所有分页加条件查询")
    public Result queryAll(@RequestParam("pageNo") Integer pageNo, @RequestParam("pageSize") Integer pageSize, @RequestBody CarComment carComment) {
        return this.carCommentService.queryAll (pageNo, pageSize, carComment);
    }
    @PostMapping("queryAllMap")
    @ApiOperation ("查询所有分页加条件查询")
    public Result queryAllMap(@RequestParam("pageNo") Integer pageNo, @RequestParam("pageSize") Integer pageSize, @RequestBody Map map){
        return this.carCommentService.queryAllMap (pageNo,pageSize,map);
    }
    /**
     * 根据ID删除
     *
     * @param id id
     * @return Result
     */
    @DeleteMapping("deleteById")
    @ApiOperation("根据ID删除")
    public Result deleteById(Integer id) {
        return new Result (ReturnStatus.SUCCESS.getReturnCode (),
                ReturnStatus.SUCCESS.getReturnMsg (), this.carCommentService.deleteById (id));
    }

    /**
     * 更新
     *
     * @param @param carComment 实例对象
     * @return Result
     */
    @PutMapping("update")
    @ApiOperation("更新")
    public Result update(@ApiParam("更新json数据") @RequestBody CarComment carComment) {
        return new Result (ReturnStatus.SUCCESS.getReturnCode (),
                ReturnStatus.SUCCESS.getReturnMsg (), this.carCommentService.update (carComment));
    }

    /**
     * 添加
     *
     * @param @param carComment 实例对象
     * @return Result
     */
    @PostMapping("insert")
    @ApiOperation("添加")
    public Result insert(@ApiParam("添加json数据") @RequestBody CarComment carComment) {
        return new Result (ReturnStatus.SUCCESS.getReturnCode (),
                ReturnStatus.SUCCESS.getReturnMsg (), this.carCommentService.insert (carComment));
    }
}